#include "regesterwindow.h"
#include "ui_regesterwindow.h"
#include "user_io.h"
#include "qmessagebox.h"
#include "register.h"
#include "iostream"
#include "qstring.h"

using namespace std;

RegesterWindow::RegesterWindow(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::RegesterWindow)
{
    ui->setupUi(this);
}

RegesterWindow::~RegesterWindow()
{
    delete ui;
}

void RegesterWindow::on_pushButton_clicked()
{
    if(ui->pwdLineEdit_2->text() == ui->pwdLineEdit->text())
        {

        QString qstr = ui->usrLineEdit->text();
        QString qstr2 = ui->pwdLineEdit->text();
        const std::string username = qstr.toStdString(); //QString转换为String
        const std::string password = qstr2.toStdString(); //QString转换为String
        //if(registerUser(username, password))

        loadUsersFromFile("D:\\QT_projects\\Login\\1.txt");
        if(registerUser(username, password)== false){
            QMessageBox::warning(this, tr("警告！"),
                        tr("重复的用户名！"),
                        QMessageBox::Yes);
        } else{
            this->destroy();
        }
        } else {
           QMessageBox::warning(this, tr("警告！"),
                       tr("两次密码不同，请重新输入！"),
                       QMessageBox::Yes);
        }
}
